<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security" %>
	
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
body {
	margin-top: 0px;
	margin-bottom: 0px;
}
.STYLE8 {color: #FF0000}
-->
</style>

<script language="javascript">
	var req;
	
	function init() {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	//根据院系ID查询DropChangeAJAXAction，获得该院系的专业列表
	function changeDropOfMajor() {
		init();
		
		var url = "dropChangeAJAX.do?method=dropChangeOfMajor&deptId=" + escape(document.forms[0].deptId.options[document.forms[0].deptId.selectedIndex].value);
		
		req.open("get", url, true);
		req.onreadystatechange = callback;
		req.send(null);
	}
	
	function callback() {
		if (4 == req.readyState) {
			if (200 == req.status) {
				eval(req.responseText);
			}
		}
	}
</script>
<script language="javascript">
	function checkForm() {
		var deptId = document.getElementById("deptId").value;
		var majorId = document.getElementById("majorId").value;
		var clazzId = document.getElementById("clazzId").value;
		var clazzName = document.getElementById("clazzName").value;
		var stuNumber = document.getElementById("stuNumber").value;
		
		if (deptId == 0) {
			alert("请选择所属院系！");
			return false;
		}
		if (majorId == 0) {
			alert("请选择所属专业！");
			return false;
		}
		if (clazzId == null || clazzId == "") {
			alert("请输入班级编号！");
			return false;
		}
		if (clazzName == null || clazzName == "") {
			alert("请输入班级名称！");
			return false;
		}
		if (stuNumber <= 0) {
			alert("请输入班级人数！");
			return false;
		}
	}
</script>


<html:form action="clazz.do?method=save" method="post" onsubmit="return checkForm();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td style="padding-right:10px;"><div align="right"></div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#c9c9c9">
      <tr>
        <td width="70%" height="22" bgcolor="#FFFFFF"><strong><span class="STYLE1">增加班级</span></strong></td>
        
      </tr>
      <tr>
        <td bgcolor="#FFFFFF">
          <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <security:authorize ifAnyGranted="ROLE_DEPT_ADMIN">
           <tr>
              <td width="15%" align="right" nowrap>所属院系：</td>
              <td width="85%" align="left">
              <html:select property="deptId">
					<html:option value="${dept.id}">${dept.deptName}</html:option>
			  </html:select>
              </td>
            </tr>
            <tr>
              <td width="15%" align="right" nowrap>所属专业：</td>
              <td width="85%"><html:select property="majorId">
					<html:option value="0">请选择</html:option>
					<c:if test="${!empty majorList}">
						<html:optionsCollection name="majorList" label="majorName" value="id"/>
					</c:if>
              </html:select>
                <span class="STYLE8">${majorIdRequired}</span></td>
            </tr>
       </security:authorize>
     <security:authorize ifAnyGranted="ROLE_ADMIN">
            <tr>
              <td width="15%" align="right" nowrap>所属院系：</td>
              <td width="85%"><html:select property="deptId" onchange="changeDropOfMajor()">
					<html:option value="0">请选择</html:option>
					<html:optionsCollection name="deptList" label="deptName" value="id"/>
              </html:select>
                <span class="STYLE8">${deptIdRequired}</span></td>
            </tr>
            <tr>
              <td width="15%" align="right" nowrap>所属专业：</td>
              <td width="85%"><html:select property="majorId">
					<html:option value="0">请选择</html:option>
					<c:if test="${!empty majorList}">
						<html:optionsCollection name="majorList" label="majorName" value="id"/>
					</c:if>
              </html:select>
                <span class="STYLE8">${majorIdRequired}</span></td>
            </tr>
      </security:authorize>
           
            <tr>
              <td width="15%" align="right" nowrap>班级编号：</td>
              <td width="85%"><html:text property="clazzId" />
                <span class="STYLE8">${clazzIdRequired}${clazzExistError }${clazzIdLenthError }</span></td>
            </tr>
            <tr>
              <td width="15%" align="right" nowrap>班级名称：</td>
              <td width="85%"><html:text property="clazzName" />
                <span class="STYLE8">${clazzNameRequired}</span></td>
            </tr>
            <tr>
              <td width="15%" align="right" nowrap>班级人数：</td>
              <td width="85%"><html:text property="stuNumber" />
                <span class="STYLE8">${stuNumberRequired}</span></td>
            </tr>            
            <tr>
              <td width="15%" align="right" nowrap>开设课程：</td>
              <td width="85%">
              	<c:if test="${!empty courseList}">
              	<%int i = 1; %>
					<c:forEach items="${courseList }" var="course">
						<html:multibox property="courseIds" value="${course.id }"></html:multibox>${course.courseName}
						<html:select property="teacherIds">
							<html:option value="0">请选择任课教师</html:option>
							<optgroup label="艺术传媒学院">
							<c:if test="${!empty artTeacherList}">
								<html:optionsCollection name="artTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="机电工程学院">
							<c:if test="${!empty mechTeacherList}">
								<html:optionsCollection name="mechTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="医学院">
							<c:if test="${!empty mediTeacherList}">
								<html:optionsCollection name="mediTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="财经学院">
							<c:if test="${!empty finaTeacherList}">
								<html:optionsCollection name="finaTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="护理学院">
							<c:if test="${!empty nurTeacherList}">
								<html:optionsCollection name="nurTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="信息技术学院">
							<c:if test="${!empty comTeacherList}">
								<html:optionsCollection name="comTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="建筑技术学院">
							<c:if test="${!empty archTeacherList}">
								<html:optionsCollection name="archTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="外语学院 ">
							<c:if test="${!empty engTeacherList}">
								<html:optionsCollection name="engTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="旅游学院">
							<c:if test="${!empty tralTeacherList}">
								<html:optionsCollection name="tralTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>
							<optgroup label="公共课部">
							<c:if test="${!empty generalTeacherList}">
								<html:optionsCollection name="generalTeacherList" label="nickname" value="id"/>
							</c:if>
							</optgroup>													
						</html:select>
						<%
							if (i++ % 3 == 0) { 
								out.print("<br/>");
							} else {
								out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
							}
						%>
					</c:forEach>
				</c:if>
			   <span class="STYLE8">${courseSelectRequired }&nbsp;&nbsp;&nbsp;&nbsp;${teacherSelectRequired }</span></td>
            </tr>            
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
              <td><html:submit value="确认增加" /> &nbsp;&nbsp;&nbsp; 
						<html:reset value="取 消" /></td>
            </tr>
          </table>        </td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td height="35">&nbsp;</td>
  </tr>
</table>
</html:form>